//
//  YBTraveldetialTableViewCell.m
//  OurTourism
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "YBTraveldetialTableViewCell.h"

@interface YBTraveldetialTableViewCell ()

@property (nonatomic, retain)UIImageView *photo;
@property (nonatomic, retain)UILabel *nameLabel;
@property (nonatomic, retain)UILabel *titleLabel;
@property (nonatomic, retain)UILabel *dateLabel;
@property (nonatomic, retain)UILabel *dieKM;
@property (nonatomic, retain)UILabel *dayCountLabel;
@property (nonatomic, retain)UILabel *KMlabel;
@property (nonatomic, retain)UILabel *lineLabelUp;
@property (nonatomic, retain)UILabel *lineLabelDown;
@property (nonatomic, retain)UILabel *lineLabelDown2;
@property (nonatomic, retain)UILabel *lineLable;
@property (nonatomic, retain)UILabel *dieLikeLabel;
@property (nonatomic, retain)UILabel *likeLabel;
@end


@implementation YBTraveldetialTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    
    self.lineLabelUp = [[UILabel alloc]init];
    [self.contentView addSubview:self.lineLabelUp];

    self.photo = [[UIImageView alloc]init];
    [self.contentView addSubview:self.photo];
 
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.font = [UIFont systemFontOfSize:10];
    [self.contentView addSubview:self.nameLabel];

    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.titleLabel];
 
    
    self.dateLabel = [[UILabel alloc]init];
    self.dateLabel.font = [UIFont systemFontOfSize:10];
    self.dateLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.dateLabel];

    
    self.dieKM = [[UILabel alloc]init];
    self.dieKM.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    self.dieKM.text = @"里程";
    self.dieKM.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.dieKM];

    
    self.dayCountLabel = [[UILabel alloc]init];
    self.dayCountLabel.font = [UIFont systemFontOfSize:11];
    self.dayCountLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.dayCountLabel];
   
    
    self.KMlabel = [[UILabel alloc]init];
    self.KMlabel.font = [UIFont systemFontOfSize:11];
    self.KMlabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.KMlabel];
  
    
    
    self.dieLikeLabel = [[UILabel alloc]init];
    self.dieLikeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
    self.dieLikeLabel.textAlignment = NSTextAlignmentCenter;
    self.dieLikeLabel.text = @"喜欢";
    [self.contentView addSubview:self.dieLikeLabel];

    
    self.likeLabel = [[UILabel alloc]init];
    self.likeLabel.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:self.likeLabel];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;

    
    
    self.lineLable = [[UILabel alloc]init];
    self.lineLable.backgroundColor = [UIColor colorWithRed:0.76 green:0.78 blue:0.8 alpha:1];
    
    [self.contentView addSubview:self.lineLable];

    
    self.lineLabelDown = [[UILabel alloc]init];
    self.lineLabelDown.backgroundColor = [UIColor colorWithRed:0.76 green:0.78 blue:0.8 alpha:1];
    
    [self.contentView addSubview:self.lineLabelDown];

    
    self.lineLabelDown2 = [[UILabel alloc]init];
    self.lineLabelDown2.backgroundColor = [UIColor colorWithRed:0.76 green:0.78 blue:0.8 alpha:1];
    [self.contentView addSubview:self.lineLabelDown2];
 
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
  
    self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
   
    self.lineLabelUp.frame = CGRectMake(10, 60, WIDTH - 20, 1);
    
    self.photo.frame = CGRectMake(WIDTH - 20 / 2 + (self.contentView.frame.size.width - 20)/8,self.lineLabelUp.frame.origin.y - (self.contentView.frame.size.width - 20)/4 , (self.contentView.frame.size.width - 20)/4, (self.contentView.frame.size.width - 20) / 4);
    self.photo.center = self.lineLabelUp.center;
    self.photo.layer.masksToBounds = YES;
    self.photo.layer.cornerRadius = self.photo.frame.size.width / 2;
    
    self.nameLabel.frame = CGRectMake(self.photo.frame.origin.x, self.photo.frame.origin.y + self.photo.frame.size.height + 10, self.contentView.frame.size.width - 10 - self.photo.frame.origin.x, 10);
    self.nameLabel.center = CGPointMake(self.photo.frame.origin.x + self.photo.frame.size.width/2, self.photo.frame.origin.y + self.photo.frame.size.width + 10);
    
    
    self.titleLabel.frame = CGRectMake(30, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height + 10, WIDTH - 60, 30);
    
    
    self.lineLabelDown.frame = CGRectMake(30, self.titleLabel.frame.origin.y + self.nameLabel.frame.size.height + 30, WIDTH - 60, 1);
    
    
    
    
    self.lineLable.frame = CGRectMake(self.lineLabelDown.frame.origin.x + self.lineLabelDown.frame.size.width / 3, self.lineLabelDown.frame.origin.y + 10, 1, 40);
    
    
    
    self.lineLabelDown2.frame = CGRectMake(self.lineLabelDown.frame.origin.x + self.lineLabelDown.frame.size.width / 3 * 2, self.lineLable.frame.origin.y, 1, 40);
    
    
    if (self.modelNotes.mileage == nil ) {
        self.dateLabel.frame = CGRectMake(self.lineLabelDown.frame.origin.x  + self.lineLabelDown.frame.size.width / 3 + 15, self.lineLabelDown.frame.origin.y + 10, self.lineLabelDown.frame.size.width/3 , 15);
        self.dateLabel.center = CGPointMake(self.photo.center.x, self.lineLabelDown.frame.origin.y + 13);
        self.dayCountLabel.frame = CGRectMake(self.dateLabel.frame.origin.x, self.dateLabel.frame.origin.y + self.dateLabel.frame.size.height + 10, self.dateLabel.frame.size.width, 10);
    }
    
    else
    {
        self.dateLabel.frame = CGRectMake(self.lineLabelDown.frame.origin.x, self.lineLabelDown.frame.origin.y + 10, self.lineLabelDown.frame.size.width/3 , 15);
        
        self.dieKM.frame = CGRectMake(self.lineLabelDown.frame.origin.x  + self.lineLabelDown.frame.size.width / 3 + 25, self.dateLabel.frame.origin.y, 60, self.dateLabel.frame.size.height);
        
        self.dieKM.center = CGPointMake(self.contentView.center.x, self.dateLabel.frame.origin.y + 8);
        self.dayCountLabel.frame = CGRectMake(self.dateLabel.frame.origin.x, self.dateLabel.frame.origin.y + self.dateLabel.frame.size.height + 10, self.dateLabel.frame.size.width, 10);
    }
    
    self.KMlabel.frame = CGRectMake(self.dieKM.frame.origin.x , self.dieKM.frame.origin.y + self.dieKM.frame.size.height + 8, 60, 10);
    
    self.dieLikeLabel.frame = CGRectMake(self.dieKM.frame.origin.x + self.dieKM.frame.size.width / 3  + 80, self.dieKM.frame.origin.y, 60, self.dieKM.frame.size.height);
    self.dieLikeLabel.center = CGPointMake(self.dieKM.center.x + self.lineLabelDown.frame.size.width / 3, self.dateLabel.frame.origin.y + 8);
    
    self.likeLabel.frame = CGRectMake(self.dieLikeLabel.frame.origin.x, self.KMlabel.frame.origin.y, 60, 10);
    
    
}

- (void)setModelNotes:(YBDestinationModel *)modelNotes
{
    if (_modelNotes != modelNotes) {
        _modelNotes = modelNotes;
    }
    
    self.titleLabel.text = modelNotes.name;
    self.dateLabel.text = modelNotes.first_day;
    self.dayCountLabel.text = [NSString stringWithFormat:@"%@%@", modelNotes.day_count, @"天"];
    self.KMlabel.text = [NSString stringWithFormat:@"%ld%@", modelNotes.mileage.integerValue, @"KM"];
    self.likeLabel.text = [NSString stringWithFormat:@"%@", modelNotes.recommendations];
    
}

- (void)setModelUser:(YBDestinationModel *)modelUser
{
    if (_modelUser != modelUser) {
        _modelUser = modelUser;
    }
    
    [self.photo sd_setImageWithURL:[NSURL URLWithString:modelUser.avatar_l] placeholderImage:nil];
    self.nameLabel.text = [NSString stringWithFormat:@"%@%@", @"by " ,modelUser.name];
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
